<?php
/**
 *	FILENAME: 		/server_app/newswire_story.php
 *	DESCRIPTION:	This backend script produces a JSON response including the story title and body given a current Newswire story ID.
 *	AUTHOR:			Casey Burkhardt 
 *	VERSION:		1.1.0
 *	LAST MODIFIED:	12/3/2010
 **/

require_once($_SERVER['DOCUMENT_ROOT'] . "/config/environment.php");
require_once($_SERVER['DOCUMENT_ROOT'] . "/libraries/functions.php");
require_once($_SERVER['DOCUMENT_ROOT'] . "/libraries/logging.php");
require_once($_SERVER['DOCUMENT_ROOT'] . "/libraries/newswire.php");

enforceSSL();
setRequestParameters();

$storyID = $_PARAMETERS["story_id"];

if (strlen($storyID) == 0) {
    $response["response_type"] = "error";
    $response["error_desc"] = "Newswire story ID not provided.";
    logWarning("No Newswire story ID supplied");
    echo(json_encode($response));
    die();
} else {
    // Obtain the issue and section information
    $timeStamp = getNewswireTimestamp();
    $storyData = getStory($storyID);

    // Check the returned results for validity.
    if ($timeStamp === FALSE || $storyData === FALSE) {
        $response["response_type"] = "error";
        $response["error_desc"] = "Unable to obtain Wildcat Newswire information.";
        logError("Unable to obtain Newswire data");
        echo(json_encode($response));
        die();
    } else {
        $response["response_type"] = "success";
        $response["issue_timestamp"] = $timeStamp;
        $response["story_data"] = $storyData;
        logAction("Returned Newswire story data");
        echo(json_encode($response));
        die();
    }
}
?>
